package logic

import (
	"context"
	"fmt"
	"videoProject/src/filemanage/rpc/file"

	"videoProject/src/filemanage/api/internal/svc"
	"videoProject/src/filemanage/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DownloadRequestLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDownloadRequestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DownloadRequestLogic {
	return &DownloadRequestLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DownloadRequestLogic) DownloadRequest(req *types.DownloadFileRequest) (resp *types.DownloadFileResponse, err error) {
	// todo: add your logic here and delete this line
	fmt.Println("Downloading................................................................")
	res, err := l.svcCtx.FileRpc.DownloadFile(l.ctx, &file.DownloadFileRequest{Name: req.Name})
	if err != nil {
		return nil, err
	}

	return &types.DownloadFileResponse{
		Message: res.Message,
		Content: res.Content,
	}, nil

}
